// ========================================================================================================================
// api：提供访问网络相应的方法以及获取用户登录信息
// ========================================================================================================================

var util = require('../utils/util.js')
var ajax = require('./ajax.js');
var base64Codec = require('./base64Codec.js');
var dataCompress = require('./dataCompress.js');

// 封装回调：提前在api调用成功前执行相应的处理
function resetCallback(callback, addSuccessFunc) {
    if (!callback) {
        callback = {
            success: function (res) {
                addSuccessFunc && addSuccessFunc(res);
            }
        }
    } else if (typeof callback === 'function') {
        var tmpCallback = callback;
        callback = {
            success: function (res) {
                addSuccessFunc && addSuccessFunc(res);
                tmpCallback(res);
            }
        };
    } else if (callback.success && typeof callback.success === 'function') {
        var tmpCallback = callback.success;
        callback.success = function (res) {
            addSuccessFunc && addSuccessFunc(res);
            tmpCallback(res);
        };
    }
    return callback
}

// 深度拷贝:一般用于提交请求时复制对象，以便于编码操作
function deepClone(obj) {
    return util.deepClone(obj);
}

// 图片上传操作
function uploadImage(filePath, callback, progressUpdateCallback) {
    var that = this;
    var imageFileKey = 'ImageFile';
    var imageApiPath = 'imageFile/xcxUploadFile';
    return ajax.uploadFile(imageApiPath, imageFileKey, filePath, callback, progressUpdateCallback);
}

function handleWhenNoLogin(msg, callback) {
    wx.showModal({
        title: '提示',
        content: msg || '进行本操作需要用户身份（需要授权本小程序获取用户信息，用户信息仅用于登录操作，无需担心），是否继续？',
        confirmText: '登录',
        success: function (res) {
            if (res.confirm) {
                callback = resetCallback(callback);
                ajax.login(callback)
            }
        }
    })
}

//获取用户信息
var user = {

    /**
     * 获取用户资料
     */
    getSubUserInfo: function (callback) {
        callback = resetCallback(callback, function (res) {
            res.User = base64Codec.UserVO.decode(res.User);
        })
        ajax.request({
            api: 'user/getSubUserInfo'
        }, callback);
    },

    /**
     * 获取用户关注和被关注的数量
     */
    getUserInfo: function (callback) {
        callback = resetCallback(callback, function (res) {
            res.User = base64Codec.UserVO.decode(res.User);
        })
        ajax.request({
            api: 'talk/getUserInfo'
        }, callback);
    },

    /**
     * 获取用户关注和被关注的数量
    * （不用校验用户身份）
    */
    sGetUserInfo: function (callback) {
        callback = resetCallback(callback, function (res) {
            res.User = base64Codec.UserVO.decode(res.User);
        })
        ajax.simpleRequest({
            api: 'talk/sGetUserInfo'
        }, callback);
    },

    /**
    * 修改用户信息
    */
    editSubUserInfo: function (userVO, callback) {
        // 所有提交修改的内容都需要将其深度拷贝一份作为提交版本（因为请求有可能发生错误）
        userVO = util.deepClone(userVO);
        userVO = base64Codec.UserVO.encode(userVO);
        callback = resetCallback(callback, function (res) { })
        ajax.request({
            api: 'user/editSubUserInfo',
            data: { Item: userVO }
        }, callback);
    },

    /**
     * 获取其它用户基本资料：api请求前不进行校验
     */
    getOtherSubUserInfo: function (userId, userSId, callback) {
        callback = resetCallback(callback, function (res) {
            res.User = base64Codec.UserVO.decode(res.User);
        })
        ajax.simpleRequest({
            api: 'user/getOtherSubUserInfo',
            data: {
                UserId: parseInt(userId || 0),
                UserSId: userSId
            }
        }, callback);
    }
}

//关注，粉丝
var follow = {
    /**
     * 获取我的关注列表
     */
    getFollowingUserList: function (nextId, pageSize, callback) {
        callback = resetCallback(callback, function (res) {
            res.Items = base64Codec.UserListVO.decode(res.Items);
        })
        ajax.request({
            api: 'follow/getFollowingUserList',
            data: {
                MinId: 0,
                MaxId: parseInt(nextId || 0),
                PageSize: parseInt(pageSize || 0),
            }
        }, callback);
    },
    /**
     * 关注
     */
    follow: function (id, sId, callback) {
        callback = resetCallback(callback);
        ajax.request({
            api: 'follow/follow',
            data: { UserSId: sId },
            checkBeforeRequest: function (authVO) {
                if (id == authVO.Id) {
                    return false;
                }
                return true;
            }
        }, callback);
    },
    /**
     * 取消关注
     */
    unFollow: function (id, SId, callback) {
        callback = resetCallback(callback)
        ajax.request({
            api: 'follow/unFollow',
            data: { UserSId: SId }
        }, callback);
    },

    /**
     * 更新对某个用户的关注状态
     */
    updateUserFollowStatus: function (status, id, sId, callback) {
        if (status == 1) { // 取消关注
            this.unFollow(id, sId, callback)
        } else { // 关注
            this.follow(id, sId, callback)
        }
    },

    /**
     * 获取我的粉丝列表
     */
    getFollowedUserList: function (nextId, pageSize, callback) {
        callback = resetCallback(callback, function (res) {
            res.Items = base64Codec.UserListVO.decode(res.Items);
        })
        ajax.request({
            api: 'follow/getFollowedUserList',
            data: {
                MinId: 0,
                MaxId: parseInt(nextId || 0),
                PageSize: parseInt(pageSize || 0),
            }
        }, callback);
    },

}
// 评论相关
var comment = {
    /**
     * 添加评论
     */
    add: function (comment, talkSId, talkUUserId, callback) {
        comment = base64Codec.CommentVO.encode(comment);
        callback = resetCallback(callback, function (res) {
            res.Item = base64Codec.CommentVO.decode(res.Item);
        })
        ajax.request({
            api: 'talk/comment/add',
            data: {
                Item: comment,
                TalkSId: talkSId,
                TalkUUserId: parseInt(talkUUserId)
            }
        }, callback);
    },
    del: function (talkId, talkSId, sectionId, talkUUserId, commentId, callback) {
        callback = resetCallback(callback, function (res) {
        })
        ajax.request({
            api: 'talk/comment/del',
            data: {
                TalkId: parseInt(talkId),
                TalkSId: talkSId,
                SectionId: parseInt(sectionId),
                TalkUUserId: parseInt(talkUUserId),
                CommentId: parseInt(commentId)
            }
        }, callback);
    },
    /**
     * 获取个人对话段落的评论列表
     */
    getList: function (talkId, sectionId, nextId, pageSize, callback) {
        callback = resetCallback(callback, function (res) {
            res.Items = base64Codec.CommentListVO.decode(res.Items);
        })
        ajax.request({
            api: 'talk/comment/getList',
            data: {
                TalkId: talkId,
                SectionId: sectionId,
                MinId: 0,
                MaxId: parseInt(nextId || 0),
                PageSize: parseInt(pageSize || 0),
                Order: '',
                Asc: -1
            }
        }, callback);
    },

    // TODO 暂时不需要 ============================================================
    // /**
    //  * 获取个人自己的评论子评论列表 
    //  */
    // getChildrenList: function (talkId, sectionId, commentId, nextId, pageSize, callback) {
    //     callback = resetCallback(callback, function (res) {
    //         res.Items = base64Codec.CommentListVO.decode(res.Items);
    //     })
    //     ajax.request({
    //         api: 'talk/comment/getChildrenList',
    //         data: {
    //             TalkId: talkId,
    //             SectionId: sectionId,
    //             CommentId: commentId,
    //             MinId: 0,
    //             MaxId: parseInt(nextId || 0),
    //             PageSize: parseInt(pageSize || 0),
    //             Order: '',
    //             Asc: -1
    //         }
    //     }, callback);
    // },

    /**
     * 获取评论列表 (不需要用户身份)
     */
    sGetList: function (talkSId, talkId, sectionId, talkUUserId, nextId, pageSize, callback) {
        callback = resetCallback(callback, function (res) {
            res.Items = base64Codec.CommentListVO.decode(res.Items);
        })
        ajax.simpleRequest({
            api: 'talk/comment/sGetList',
            data: {
                TalkSId: talkSId,
                TalkId: parseInt(talkId),
                SectionId: parseInt(sectionId),
                TalkUUserId: parseInt(talkUUserId),
                MinId: 0,
                MaxId: parseInt(nextId || 0),
                PageSize: parseInt(pageSize || 0),
                Order: '',
                Asc: -1
            }
        }, callback);
    },

    // TODO 暂时不需要 ============================================================
    // /**
    //  * 获取评论子评论列表 (不需要用户身份)
    //  */
    // sGetChildrenList: function (talkId, sectionId, commentId, nextId, pageSize, callback) {
    //     callback = resetCallback(callback, function (res) {
    //         res.Items = base64Codec.CommentListVO.decode(res.Items);
    //     })
    //     ajax.simpleRequest({
    //         api: 'talk/comment/sGetChildrenList',
    //         data: {
    //             TalkId: talkId,
    //             SectionId: sectionId,
    //             CommentId: commentId,
    //             MinId: 0,
    //             MaxId: parseInt(nextId || 0),
    //             PageSize: parseInt(pageSize || 0),
    //             Order: '',
    //             Asc: -1
    //         }
    //     }, callback);
    // },

    /**
     * 点赞评论
     */
    like: function (talkId, parentCommentId, talkSId, sectionId, commentId, talkUUserId, callback) {
        callback = resetCallback(callback)
        ajax.request({
            api: 'talk/comment/like',
            data: {
                TalkSId: talkSId,
                ParentCommentId: parseInt(parentCommentId),
                TalkId: parseInt(talkId),
                SectionId: parseInt(sectionId),
                CommentId: parseInt(commentId),
                TalkUUserId: parseInt(talkUUserId)
            }
        }, callback);
    },

    /**
     * 取消点赞评论
     */
    unLike: function (talkId, talkSId, sectionId, commentId, talkUUserId, callback) {
        callback = resetCallback(callback)
        ajax.request({
            api: 'talk/comment/unLike',
            data: {
                TalkSId: talkSId,
                TalkId: parseInt(talkId),
                SectionId: parseInt(sectionId),
                CommentId: parseInt(commentId),
                TalkUUserId: parseInt(talkUUserId)
            }
        }, callback);
    }
}
// ===========================================================
// 对话
var talk = {
    /**
     * 新建对话
     */
    add: function (talkVO, callback) {
        talkVO = deepClone(talkVO);
        talkVO = base64Codec.TalkVO.encode(talkVO);
        talkVO = dataCompress.TalkVO.compressForSave(talkVO);
        callback = resetCallback(callback, function (res) {
            res.Item = base64Codec.TalkVO.decode(res.Item);
        })
        ajax.request({
            api: 'talk/add',
            data: { Item: talkVO }
        }, callback);
    },

    /**
     * 发布对话
     */
    publish: function (talkVO, callback) {
        talkVO = deepClone(talkVO);
        talkVO = base64Codec.TalkVO.encode(talkVO);
        talkVO = dataCompress.TalkVO.compressForSave(talkVO);
        callback = resetCallback(callback, function (res) {
            res.Item = base64Codec.TalkVO.decode(res.Item);
        })
        ajax.request({
            api: 'talk/publish',
            data: { Item: talkVO }
        }, callback);
    },

    /**
     * 获取对话
     */
    get: function (id, callback) {
        callback = resetCallback(callback, function (res) {
            res.Item = base64Codec.TalkVO.decode(res.Item);
        })
        ajax.request({
            api: 'talk/get',
            data: { Id: parseInt(id || 0) }
        }, callback);
    },

    /**
     * 获取对话(无需要身体校验)
     */
    sget: function (sId, talkUUserid, callback) {
        callback = resetCallback(callback, function (res) {
            res.Item = base64Codec.TalkVO.decode(res.Item);
        })
        ajax.simpleRequest({
            api: 'talk/sget',
            data: { SId: sId, TalkUUserId: parseInt(talkUUserid) }
        }, callback);
    },

    /**
     * 编辑对话
     */
    edit: function (talkVO, callback) {
        talkVO = deepClone(talkVO);
        talkVO = base64Codec.TalkVO.encode(talkVO);
        talkVO = dataCompress.TalkVO.compressForSave(talkVO);
        callback = resetCallback(callback, function (res) {
            res.Item = base64Codec.TalkVO.decode(res.Item);
        })
        ajax.request({
            api: 'talk/edit',
            data: { Item: talkVO }
        }, callback);
    },

    /**
     * 删除对话
     */
    del: function (id, callback) {
        ajax.request({
            api: 'talk/del',
            data: { Id: parseInt(id || 0) }
        }, resetCallback(callback));
    },

    /**
     * 发布对话
     */
    discard: function (talkVO, callback) {
        talkVO = dataCompress.TalkVO.compressForDiscard(talkVO);
        ajax.request({
            api: 'talk/discard',
            data: { Item: talkVO }
        }, callback);
    },

    /**
     * 获取我的对话列表:默认倒序排序
     */
    getList: function (nextId, pageSize, callback) {
        callback = resetCallback(callback, function (res) {
            res.Items = base64Codec.TalkListVO.decode(res.Items);
        })
        ajax.request({
            api: 'talk/getList',
            data: {
                MinId: 0,
                MaxId: parseInt(nextId || 0),
                PageSize: parseInt(pageSize || 0),
                Order: '',
                Asc: -1
            }
        }, callback);
    },

    /**
     * 收藏对话
     */
    collect: function (sId, talkUUserId, callback) {
        callback = resetCallback(callback, function (res) { })
        ajax.request({
            api: 'talk/collect',
            data: { SId: sId, TalkUUserId: parseInt(talkUUserId) }
        }, callback);
    },

    /**
     * 取消收藏对话
     */
    unCollect: function (sId, talkUUserId, callback) {
        callback = resetCallback(callback, function (res) { })
        ajax.request({
            api: 'talk/unCollect',
            data: { SId: sId, TalkUUserId: parseInt(talkUUserId) }
        }, callback);
    },
    /**
     * 取消收藏通过seqPageId（当对话内容找不到时使用）
     */
    unCollectBySeqPageId: function (seqPageId, callback) {
        callback = resetCallback(callback, function (res) { })
        ajax.request({
            api: 'talk/unCollectBySeqPageId',
            data: { SeqPageId: parseInt(seqPageId) }
        }, callback);
    },

    /**
     * 更新用户对对话的收藏状态
     * status： 1、未收藏 2、已收藏
     */
    updateCollectStatus: function (status, sId, talkUUserId, callback) {
        if (status == 2) {
            this.collect(sId, talkUUserId, callback);
        } else {
            this.unCollect(sId, talkUUserId, callback);
        }
    },

    /**
     * 获取我的收藏列表:默认倒序排序
     */
    getCollectList: function (nextId, pageSize, callback) {
        callback = resetCallback(callback, function (res) {
            res.Items = base64Codec.TalkListVO.decode(res.Items);
        })
        ajax.request({
            api: 'talk/getCollectList',
            data: {
                MinId: 0,
                MaxId: parseInt(nextId || 0),
                PageSize: parseInt(pageSize || 0),
                Order: '',
                Asc: -1
            }
        }, callback);
    },

    /**
     * 点赞对话
     */
    like: function (sId, talkUUserId, callback) {
        ajax.request({
            api: 'talk/like',
            data: { SId: sId, TalkUUserId: talkUUserId }
        }, callback);
    },

    /**
     *  取消点赞对话
     */
    unLike: function (sId, talkUUserId, callback) {
        ajax.request({
            api: 'talk/unLike',
            data: { SId: sId, TalkUUserId: talkUUserId }
        }, callback);
    },

    /**
     * 更新点赞状态：
     * status： 1、未点赞 2、已点赞
     */
    updateLikeStatus: function (status, sId, talkUUserId, callback) {
        if (status == 2) {
            this.like(sId, talkUUserId, callback);
        } else {
            this.unLike(sId, talkUUserId, callback);
        }
    },

    /**
     *  获取点赞用户列表:默认倒序排序
     */
    sGetLikeUsertList: function (sId, nextId, pageSize, callback) {
        callback = resetCallback(callback, function (res) {
            res.Items = base64Codec.UserListVO.decode(res.Items);
        })
        ajax.simpleRequest({
            api: 'talk/sGetLikeUsertList',
            data: {
                SId: sId,
                MinId: 0,
                MaxId: parseInt(nextId || 0),
                PageSize: parseInt(pageSize || 0),
                Order: '',
                Asc: -1
            }
        }, callback);
    },

    /**
     * 获取点赞用户列表:默认倒序排序
     */
    getLikeUsertList: function (id, nextId, pageSize, callback) {
        callback = resetCallback(callback, function (res) {
            res.Items = base64Codec.UserListVO.decode(res.Items);
        })
        ajax.request({
            api: 'talk/getLikeUsertList',
            data: {
                Id: parseInt(id),
                MinId: 0,
                MaxId: parseInt(nextId || 0),
                PageSize: parseInt(pageSize || 0),
                Order: '',
                Asc: -1
            }
        }, callback);
    },

    /**
     * 获取对对话的操作状态
     */
    sGetUserStatus: function (sId, talkUUserId, callback) {
        callback = resetCallback(callback, function (res) {
            res.Item = res.Item || {};
        })
        ajax.simpleRequest({
            api: 'talk/sGetUserStatus',
            data: {
                SId: sId,
                TalkUUserId: parseInt(talkUUserId)
            }
        }, callback);
    },

    /**
     * 获取猜你喜欢列表
     */
    getGuessList: function (callback) {
        callback = resetCallback(callback, function (res) {

        })
        ajax.request({
            api: 'talk/getGuessList',
            data: {}
        }, callback);
    },


    /**
     *  获取推荐对话列表:默认倒序排序
     */
    getRecommendList: function (nextId, pageSize, callback) {
        callback = resetCallback(callback, function (res) {
            res.Items = base64Codec.TalkListVO.decode(res.Items);
        })
        ajax.request({
            api: 'talk/getRecommendList',
            data: {
                MinId: 0,
                MaxId: parseInt(nextId || 0),
                PageSize: parseInt(pageSize || 0),
                Order: '',
                Asc: -1
            }
        }, callback);
    },

    /**
     * 获取关注作者的对话列表:默认倒序排序
     */
    getFollowList: function (nextId, pageSize, callback) {
        callback = resetCallback(callback, function (res) {
            res.Items = base64Codec.TalkListVO.decode(res.Items);
        })
        ajax.request({
            api: 'talk/getFollowList',
            data: {
                MinId: 0,
                MaxId: parseInt(nextId || 0),
                PageSize: parseInt(pageSize || 0),
                Order: '',
                Asc: -1
            }
        }, callback);
    },

    // /**
    //  *  获取最热列表:默认倒序排序
    //  */
    // getHotList: function (nextId, pageSize, callback) {
    //     callback = resetCallback(callback, function (res) {
    //         res.Items = base64Codec.TalkListVO.decode(res.Items);
    //     })
    //     ajax.request({
    //         api: 'talk/getHotList',
    //         data: {
    //             MinId: 0,
    //             MaxId: parseInt(nextId || 0),
    //             PageSize: parseInt(pageSize || 0),
    //             Order: '',
    //             Asc: -1
    //         }
    //     }, callback);
    // },

    // /**
    //  * 获取最新列表:默认倒序排序
    //  */
    // getNewList: function (nextId, pageSize, callback) {
    //     callback = resetCallback(callback, function (res) {
    //         res.Items = base64Codec.TalkListVO.decode(res.Items);
    //     })
    //     ajax.request({
    //         api: 'talk/getNewList',
    //         data: {
    //             MinId: 0,
    //             MaxId: parseInt(nextId || 0),
    //             PageSize: parseInt(pageSize || 0),
    //             Order: '',
    //             Asc: -1
    //         }
    //     }, callback);
    // },

    /**
    * 获取作者主页的文章列表：默认倒序排序
    */
    getHomePageList: function (userSId, nextId, pageSize, callback) {
        callback = resetCallback(callback, function (res) {
            res.Items = base64Codec.TalkListVO.decode(res.Items);
        })
        ajax.simpleRequest({
            api: 'talk/getHomePageList',
            data: {
                UserSId: userSId,
                MinId: 0,
                MaxId: parseInt(nextId || 0),
                PageSize: parseInt(pageSize || 0),
                Order: '',
                Asc: -1
            }
        }, callback);
    }
};

/**
 * 对话角色
 */
var role = {
    /**
     * 新建角色
     */
    add: function (roleVO, callback) {
        roleVO = deepClone(roleVO);
        roleVO = base64Codec.RoleVO.encode(roleVO);
        callback = resetCallback(callback, function (res) {
            res.Item = base64Codec.RoleVO.decode(res.Item);
        })
        ajax.request({
            api: 'role/add',
            data: { Item: roleVO }
        }, callback);
    },

    // /**
    //  * 获取角色
    //  */
    // get: function (id, callback) {
    //     callback = resetCallback(callback, function (res) {
    //         res.Item = base64Codec.RoleVO.decode(res.Item);
    //     })
    //     ajax.request({
    //         api: 'role/get',
    //         data: { Id: parseInt(id || 0) }
    //     }, callback);
    // },

    /**
     * 编辑角色
     */
    edit: function (roleVO, callback) {
        roleVO = deepClone(roleVO);
        roleVO = base64Codec.RoleVO.encode(roleVO);
        callback = resetCallback(callback, function (res) {
            res.Item = base64Codec.RoleVO.decode(res.Item);
        })
        ajax.request({
            api: 'role/edit',
            data: { Item: roleVO }
        }, callback);
    },

    /**
     * 删除角色
     */
    del: function (id, callback) {
        ajax.request({
            api: 'role/del',
            data: { Id: parseInt(id || 0) }
        }, resetCallback(callback));
    },

    // /**
    //  * 获取某对话角色列表
    //  */
    // getList: function (talkId, pageNumber, pageSize, callback) {
    //     callback = resetCallback(callback, function (res) {
    //         res.Items = base64Codec.RoleListVO.decode(res.Items);
    //     })
    //     ajax.request({
    //         api: 'role/getList',
    //         data: {
    //             TalkId: parseInt(talkId || 0),
    //             PageNumber: parseInt(pageNumber || 0),
    //             pageSize: parseInt(pageSize || 0)
    //         }

    //     }, resetCallback(callback));
    // },

    // /**
    //  * 把角色复制一份到故事角色库
    //  */
    // copy2Story: function (id, callback) {
    //     ajax.request({
    //         api: 'role/copy2Story',
    //         data: { Id: parseInt(id || 0) }
    //     }, resetCallback(callback));
    // },

    // /**
    //  *  把角色复制一份到故事角色库
    //  */
    // copy2User: function (id, callback) {
    //     ajax.request({
    //         api: 'role/copy2User',
    //         data: { Id: parseInt(id || 0) }
    //     }, resetCallback(callback));
    // }
};

// TODO 暂时没有使用到 ============================================================
// /**
//  * 故事角色
//  */
// var storyRole = {
//     // 新建角色
//     add: function (roleVO, callback) {
//         roleVO = deepClone(roleVO);
//         roleVO = base64Codec.RoleVO.encode(roleVO);
//         callback = resetCallback(callback, function (res) {
//             res.Item = base64Codec.RoleVO.decode(res.Item);
//         })
//         ajax.request({
//             api: 'storyRole/add',
//             data: { Item: roleVO }
//         }, callback);
//     },

//     /**
//      * 获取角色
//      */
//     get: function (id, callback) {
//         callback = resetCallback(callback, function (res) {
//             res.Item = base64Codec.RoleVO.decode(res.Item);
//         })
//         ajax.request({
//             api: 'storyRole/get',
//             data: { Id: parseInt(id || 0) }
//         }, callback);
//     },

//     /**
//      * 编辑角色
//      */
//     edit: function (roleVO, callback) {
//         roleVO = deepClone(roleVO);
//         roleVO = base64Codec.RoleVO.encode(roleVO);
//         callback = resetCallback(callback, function (res) {
//             res.Item = base64Codec.RoleVO.decode(res.Item);
//         })
//         ajax.request({
//             api: 'storyRole/edit',
//             data: { Item: roleVO }
//         }, callback);
//     },

//     /**
//      * 删除角色
//      */
//     del: function (id, callback) {
//         ajax.request({
//             api: 'storyRole/del',
//             data: { Id: parseInt(id || 0) }
//         }, resetCallback(callback));
//     },

//     /**
//      *  获取某对话角色列表
//      */
//     getList: function (storyId, pageNumber, pageSize, callback) {
//         callback = resetCallback(callback, function (res) {
//             res.Items = base64Codec.RoleListVO.decode(res.Items);
//         })
//         ajax.request({
//             api: 'storyRole/getList',
//             data: {
//                 StoryId: parseInt(storyId || 0),
//                 PageNumber: parseInt(pageNumber || 0),
//                 pageSize: parseInt(pageSize || 0)
//             }

//         }, resetCallback(callback));
//     },

//     /**
//      * 把角色复制一份到故事角色库
//      */
//     copy2User: function (id, callback) {
//         ajax.request({
//             api: 'storyRole/copy2User',
//             data: { Id: parseInt(id || 0) }
//         }, resetCallback(callback));
//     }
// };

// TODO 暂时没有使用到 ============================================================
// /**
//  * 用户常用角色
//  */
// var userRole = {
//     /**
//      *  新建角色
//      */
//     add: function (roleVO, callback) {
//         roleVO = deepClone(roleVO);
//         roleVO = base64Codec.RoleVO.encode(roleVO);
//         callback = resetCallback(callback, function (res) {
//             res.Item = base64Codec.RoleVO.decode(res.Item);
//         })
//         ajax.request({
//             api: 'userRole/add',
//             data: { Item: roleVO }
//         }, callback);
//     },

//     /**
//      * 获取角色
//      */
//     get: function (id, callback) {
//         callback = resetCallback(callback, function (res) {
//             res.Item = base64Codec.RoleVO.decode(res.Item);
//         })
//         ajax.request({
//             api: 'userRole/get',
//             data: { Id: parseInt(id || 0) }
//         }, callback);
//     },

//     /**
//      * 编辑角色
//      */
//     edit: function (roleVO, callback) {
//         roleVO = deepClone(roleVO);
//         roleVO = base64Codec.RoleVO.encode(roleVO);
//         callback = resetCallback(callback, function (res) {
//             res.Item = base64Codec.RoleVO.decode(res.Item);
//         })
//         ajax.request({
//             api: 'userRole/edit',
//             data: { Item: roleVO }
//         }, callback);
//     },

//     /**
//      *  删除角色
//      */
//     del: function (id, callback) {
//         ajax.request({
//             api: 'userRole/del',
//             data: { Id: parseInt(id || 0) }
//         }, resetCallback(callback));
//     },

//     /**
//      * 获取某对话角色列表
//      */
//     getList: function (pageNumber, pageSize, callback) {
//         callback = resetCallback(callback, function (res) {
//             res.Items = base64Codec.RoleListVO.decode(res.Items);
//         })
//         ajax.request({
//             api: 'userRole/getList',
//             data: {
//                 PageNumber: parseInt(pageNumber || 0),
//                 pageSize: parseInt(pageSize || 0)
//             }

//         }, resetCallback(callback));
//     }
// };


module.exports = {
    // ============================================================
    // 辅助方法

    /**
     * 获取用户登录信息
     */
    getCacheOfAuthVO: ajax.getCacheOfAuthVO,

    /**
     * 显示加载中...
     */
    showLoading: function (obj) {
        ajax.showLoading(obj);
        return this;
    },

    /**
     * 隐藏加载中...
     */
    hideLoading: function () {
        ajax.hideLoading();
        return this;
    },

    /**
     * 图片上传
     */
    uploadImage: uploadImage,

    /**
     * 检查是否满足登录 callback {yes: function, no: function}
     */
    checkIsLogin: ajax.checkIsLogin,

    /**
     * 登录
     */
    login: ajax.login,

    /**
     * 未登录情况下，的处理
     */
    handleWhenNoLogin: handleWhenNoLogin,


    // ============================================================
    // api请求模块

    user: user,
    follow: follow,
    talk: talk,
    role: role,
    user: user,
    // storyRole: storyRole,
    // userRole: userRole,
    follow: follow,
    comment: comment
}